package com.yf1706.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.QuestionBank;
import com.yf1706.bean.SingleChoice;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.jpa.singleselectJDAO;
import com.yf1706.dao.mybatis.ISingleChoiceMDAO;

@Service
public class singleChoiceService {
	@Autowired
	private singleselectJDAO ssjdao;
	@Autowired
	private ISingleChoiceMDAO smdao;
	@Autowired
	private questionBankJDAO qbjdao;
	
	/*通过题库查到单选表中此题库所有的题*/
	public List<SingleChoice> findByQuestionBank(QuestionBank q){
		System.err.println(ssjdao.findByQuestionBank(q).get(1).getAnswer());
		return ssjdao.findByQuestionBank(q);
	}
	
	public List<SingleChoice> querybyQbId(int qbId){
		return smdao.querybyQbId(qbId);
	}
	
	//在题库添加题目
	public void questionbankAddSingleChoice(String answer,String a,String b,String c,String d,String examQuestion,String qbId,String createPeople){
		SingleChoice sc=new SingleChoice();
		sc.setA(a);
		sc.setAnswer(answer);
		sc.setB(b);
		sc.setC(c);
		sc.setD(d);
		sc.setCreatePeople(createPeople);
		sc.setCreateDate(new Date());
		sc.setExamQuestion(examQuestion);
		int qbid=Integer.parseInt(qbId);
		sc.setQuestionBank(qbjdao.findByQbId(qbid));
		ssjdao.save(sc);
	}
	
	public void deleteQuestionBankSingleChoice(int singleChoiceId) {
		ssjdao.deleteById(singleChoiceId);
	}
	
	//查询单选表中的所有单选题，（用mybatis）
	public List<SingleChoice> queryAllSingleChoice() {
		return smdao.queryAllSingleChoice();
	}
	//通过题库和考题查询单选题
	public List<SingleChoice> queryAllByQbIdAndExamQuestion(int qbId,String examQuestion) {
		return smdao.queryAllByQbIdAndExamQuestion(qbId,examQuestion);
	}

	public void deletSingleChoiceById(int singleChoiceId) {
		ssjdao.deleteById(singleChoiceId);
		
	}
	
	public List<SingleChoice> findBySingleChoiceId(int singleChoiceId) {
		return ssjdao.findBySingleChoiceId(singleChoiceId);
	}

	public void changeSingleChocie(SingleChoice s) {
	
		ssjdao.save(s);
		
	}

	public void add(String examQuestion, String a, String b, String c, String d, String answer, int qbId,String userName) {
		SingleChoice s=new SingleChoice();
		s.setA(a);
		s.setB(b);
		s.setC(c);
		s.setD(d);
		s.setCreatePeople(userName);
		s.setAnswer(answer);
		s.setCreateDate(new Date());
		s.setQuestionBank(qbjdao.findByQbId(qbId));
		s.setExamQuestion(examQuestion);
		ssjdao.save(s);
		
	}


}
